package com.shimao.celnet.payment.service.impl;

import com.github.pagehelper.PageHelper;
import com.shimao.celnet.payment.form.BEstateForm;
import com.shimao.celnet.payment.mapper.BEstateMapper;
import com.shimao.celnet.payment.model.BEstate;
import com.shimao.celnet.payment.service.BEstateService;
import org.apache.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 小区管理
 * Created by ensure on 2017/12/3.
 */
@Service
public class BEstateServiceImpl extends BaseServiceImpl<BEstate> implements BEstateService {
    protected Logger logger = Logger.getLogger(this.getClass());

    @Autowired(required = false)
    private BEstateMapper localMapper;



    /**
     * 分页查询
     * @param formBean
     * @param pageNum
     * @param length
     * @return
     */
    @Override
    public BEstateForm getByPage(BEstateForm formBean, int pageNum, int length) {
        logger.info("分页查询--开始");
        //分页查询
        Map<String,String> pMap = new HashMap<String,String>();
        pMap.put("areaGuid",formBean.getAreaGuid());
        pMap.put("estateName",formBean.getEstateName());
        pMap.put("sfName",formBean.getSfName());
        pMap.put("cityName",formBean.getCityName());
        pMap.put("provinceName",formBean.getProvinceName());

        //分页查询
        PageHelper.startPage(pageNum, length);

        List<BEstateForm> tableList = localMapper.selectPageList(pMap);


        //分页查询
        PageHelper.startPage(pageNum, length);
        formBean.setPageInfo(tableList);


        return  formBean;
    }

    /**
     * 根据SF-GUID取得
     * @param sfGuid
     * @return
     */
    @Override
    public BEstateForm getBySfGuid(String sfGuid) {
        logger.info("分页查询--开始");
        //分页查询
        Map<String,String> pMap = new HashMap<String,String>();
        pMap.put("sfGuid",sfGuid);

        List<BEstateForm> tableList = localMapper.selectPageList(pMap);
        if(tableList.size()>0){
            return tableList.get(0);
        }else{
            return  new BEstateForm();
        }
    }


    /**
     *新增权限保存
     * @return
     */
    @Override
    public int save(BEstate sBean){
        int retCnt=0;
        String loginUserGuid = (String) SecurityUtils.getSubject().getSession().getAttribute("userSessionId");
        sBean.setUpdateUserGuid(loginUserGuid);
        sBean.setCreatedUserGuid(loginUserGuid);
        sBean.setGuid(getGuid());//guid
        retCnt = super.save(sBean);

        return retCnt;
    }

    /**
     *修改权限保存
     * @return
     */
    @Override
    public int update(BEstate sBean){
        String loginUserGuid = (String) SecurityUtils.getSubject().getSession().getAttribute("userSessionId");
        sBean.setUpdateUserGuid(loginUserGuid);
        int retCnt = super.update(sBean);

        return retCnt;
    }

}
